package lambdademo;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * Creared with IntelliJ IDEA.
 * Description:
 * User:yxd
 * Date:2022-03-02
 * Time:16:01
 */
public class Test2 {
    public static void main(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("hello");
        arrayList.add("a");
        arrayList.add("b");
        arrayList.add("c");
        arrayList.forEach(new Consumer<String>() {//函数是借口  遍历list里面的所有元素
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        arrayList.forEach(s-> System.out.println(s));//这样就直接可以遍历里面所有元素了
        arrayList.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });
        arrayList.sort((o1,o2)->o1.compareTo(o2));//排序


        Map<Integer,String> map = new HashMap<>();
        map.put(1,"a");
        map.put(2,"b");
        map.put(3,"c");
        map.put(4,"d");
        map.put(5,"e");
        map.forEach(new BiConsumer<Integer, String>() {
            @Override
            public void accept(Integer key, String value) {
                System.out.println("key" + key + "value" + value);
            }
        });
        map.forEach((key,value)-> System.out.println("key" + key + "value" + value));
    }
}
